/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package org.ing.sisval.gui.control.model;

import java.util.List;
import org.ing.sisval.be.BEDistribucion;
import org.rx.cr.gui.table.AbstractTableModel;

public class ModeloDistribucionAsignado extends AbstractTableModel<BEDistribucion> {

    private final List<BEDistribucion> List;

    public ModeloDistribucionAsignado() {
        setTitles(new String[]{"Nombre", "Cantidad"});
        this.List = null;

    }

    public ModeloDistribucionAsignado(List<BEDistribucion> List) {
        setTitles(new String[]{"Nombre", "Cantidad"});
        this.List = List;
    }

    @Override
    public Object getObjectCell(int fila, int columna) {
        switch (columna) {
            case 0:
                return get(fila).getNombre();
            case 1:
                return get(fila).getCantidad();
            default:
                return null;
        }

    }

    @Override
    public boolean isCellEditable(int rowIndex, int colIndex) {
        return true;
    }

    @Override
    public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
        BEDistribucion be = List.get(rowIndex);
        if (0 == columnIndex) {
            be.setNombre(aValue.toString());
        } else if (1 == columnIndex) {
            be.setCantidad(Integer.parseInt(aValue.toString()));
        }

    }

    @Override
    public int getColumnCount() {
        return 2;
    }
}
